package io.renren.modules.sys.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.modules.sys.entity.SongsetEntity;
import io.renren.modules.sys.entity.SongsetRecommendEntity;
import io.renren.modules.sys.service.SongsetService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.SongsetNewEntity;
import io.renren.modules.sys.service.SongsetNewService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author wangyi
 * @email 794651397@qq.com
 * @date 2018-02-24 10:46:32
 */
@RestController
@RequestMapping("/sys/songsetnew")
public class SongsetNewController {
	@Autowired
	private SongsetNewService songsetNewService;

    @Autowired
    private SongsetService songsetService;
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<SongsetEntity> songRecommendList = songsetNewService.queryList(query);
        int total = songsetNewService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(songRecommendList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Long id){
		SongsetNewEntity songsetNew = songsetNewService.queryObject(id);
		
		return R.ok().put("songsetNew", songsetNew);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody SongsetNewEntity songsetNew){
		songsetNewService.save(songsetNew);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody SongsetNewEntity songsetNew){
		songsetNewService.update(songsetNew);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Long[] ids){
		songsetNewService.deleteBatch(ids);
		
		return R.ok();
	}

    /**
     * 列表
     */
    @RequestMapping("/listAll")
    public R listAll(@RequestParam Map<String, Object> params){
        List<SongsetEntity> songsetNewList = songsetNewService.queryListAll(params);

        return R.ok().put("list", songsetNewList);
    }

    /**
     * 配置
     */
    @RequestMapping("/checkSong")
    public R checkSong(@RequestBody List<SongsetNewEntity> sList){
        songsetNewService.deleteAll();
        for (SongsetNewEntity songsetNewEntity : sList) {
            songsetNewEntity.setCreateTime(new Date());
        }
        songsetNewService.insertBatch(sList);
        return R.ok();
    }

    /**
     * 列表
     */
    @RequestMapping("/recommendList")
    public R recommendList(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<SongsetEntity> songsetList = songsetService.queryListNewSort(query);
        int total = songsetService.queryTotalNewSort(query);

        PageUtils pageUtil = new PageUtils(songsetList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }
	
}
